package com.ruoyi.system.controller.person;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Econtract;
import com.ruoyi.system.domain.SysIcon;
import com.ruoyi.system.service.IEcontractService;
import com.ruoyi.system.service.ISysIconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图标管理Controller
 *
 * @author ruoyi
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/system/icon")
public class SysIconController extends BaseController
{
    @Autowired
    private ISysIconService sysIconService;

    /**
     * 查询图标管理列表
     */
    @RequiresPermissions("system:icon:list")
    @GetMapping("/list")
    public TableDataInfo list(SysIcon sysIcon)
    {
        startPage();
        List<SysIcon> list = sysIconService.selectSysIconList(sysIcon);
        return getDataTable(list);
    }

    /**
     * 导出图标管理列表
     */
    @RequiresPermissions("system:icon:export")
    @Log(title = "图标管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysIcon sysIcon)
    {
        List<SysIcon> list = sysIconService.selectSysIconList(sysIcon);
        ExcelUtil<SysIcon> util = new ExcelUtil<SysIcon>(SysIcon.class);
        util.exportExcel(response, list, "图标管理数据");
    }

    /**
     * 获取图标管理详细信息
     */
    @RequiresPermissions("system:icon:query")
    @GetMapping(value = "/{iconId}")
    public AjaxResult getInfo(@PathVariable("iconId") Long iconId)
    {
        return success(sysIconService.selectSysIconByIconId(iconId));
    }

    /**
     * 新增图标管理
     */
    @RequiresPermissions("system:icon:add")
    @Log(title = "图标管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysIcon sysIcon)
    {
        return toAjax(sysIconService.insertSysIcon(sysIcon));
    }

    /**
     * 修改图标管理
     */
    @RequiresPermissions("system:icon:edit")
    @Log(title = "图标管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysIcon sysIcon)
    {
        return toAjax(sysIconService.updateSysIcon(sysIcon));
    }

    /**
     * 删除图标管理
     */
    @RequiresPermissions("system:icon:remove")
    @Log(title = "图标管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iconIds}")
    public AjaxResult remove(@PathVariable Long[] iconIds)
    {
        return toAjax(sysIconService.deleteSysIconByIconIds(iconIds));
    }
}
